﻿using System;
using System.Linq;
using System.Runtime.Serialization;

namespace TraceView.UI.Entities
{
    [DataContract]
    public class Profile : BaseEntity
    {
        [DataMember] private string _configPath;
        [DataMember] private DateTime _creationDate;      
        [DataMember] private string _listener;
        [DataMember] private string _name;
        private bool _isChecked;

        public string Name
        {
            get { return _name; }
            set { SetProperty(() => Name, ref _name, value); }
        }

        public string ConfigPath
        {
            get { return _configPath; }
            set { SetProperty(() => ConfigPath, ref _configPath, value); }
        }

        public string Listener
        {
            get { return _listener; }
            set { SetProperty(() => Listener, ref _listener, value); }
        }

        public DateTime CreationDate
        {
            get { return _creationDate; }
            set { SetProperty(() => CreationDate, ref _creationDate, value); }
        }


        public bool IsChecked
        {
            get { return _isChecked; }
            set { SetProperty(() => IsChecked, ref _isChecked, value); }
        }
    }

    public class Profiles : BaseEntityCollection<Profile>
    {
        public string Validate(Profile item)
        {
            Profile firstOrDefault = this.FirstOrDefault(
                profile => profile.Name.Equals(item.Name, StringComparison.OrdinalIgnoreCase));
            return firstOrDefault != null ? "A profile with the same name already exists." : null;
        }
    }
}